package com.fishery.logistics.controller;


import com.fishery.entity.Result;
import com.fishery.logistics.entity.Order;
import com.fishery.logistics.entity.vo.OrderVo;
import com.fishery.logistics.entity.vo.SearchMap;
import com.fishery.logistics.service.OrderService;
import com.fishery.logistics.utils.ConvertUtil;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author run
 * @since 2021-01-23
 */
@Api(tags = "物流订单接口")
@CrossOrigin
@RestController
@RequestMapping("/logistics/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/")
    @ApiOperation("创建物流订单")
    public Result createOrder(@RequestBody @ApiParam(required = true,value = "orderVo") OrderVo orderVo){
        //返回创建的物流订单的id
        return Result.success().data(orderService.createOrder(orderVo));
    }

    @PutMapping("/")
    @ApiOperation("修改物流订单")
    public Result updateOrder(@RequestBody @ApiParam(required = true,value = "orderVo") OrderVo orderVo){
        return orderService.updateOrder(orderVo)
                ? Result.success("修改成功") : Result.error("修改失败");
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除物流订单")
    public Result deleteOrder(@PathVariable(value = "id") String orderId){
        return orderService.deleteOrder(orderId)
                ? Result.success("删除成功") : Result.error("删除失败");
    }

    @GetMapping("/{id}")
    @ApiOperation("根据物流订单id获取物流订单信息")
    public Result searchOrderById(@PathVariable(value = "id") String orderId){
        return Result.success().data(orderService.searchOrderById(orderId));
    }

    /**
     * 条件筛选+分页
     * @param searchMap
     * @param baseId
     * @param page
     * @param size
     * @return
     */
    @PutMapping("/{id}/{page}/{size}")
    @ApiOperation("根据基地id分页获取物流订单")
    public Result searchOrderOfBase(@RequestBody @ApiParam(value = "SearchMap",required = false)SearchMap searchMap
                                    , @PathVariable(value = "id") String baseId
                                    , @PathVariable(value = "page") Integer page
                                    , @PathVariable(value = "size") Integer size){
        return Result.success().data(orderService.searchOrderOfBase(baseId,page,size,searchMap));
    }

     /**
     * 条件筛选 不分页
     * @param searchMap
     * @param baseId
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("根据基地id获取全部物流订单")
    public Result searchOrderOfBase(@RequestBody @ApiParam(value = "SearchMap",required = false) SearchMap searchMap
                                    ,@PathVariable(value = "id") String baseId){
        return Result.success().data(orderService.searchOrderOfBase(baseId,searchMap));
    }

}

